package cn.yuanqiao.web.controller.archive.management;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.management.domain.YqZpjl;
import cn.yuanqiao.archive.management.domain.YqZpmx;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.management.domain.YqPgg;
import cn.yuanqiao.archive.management.service.IYqPggService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 盘规格Controller
 * 
 * @author sy
 * @date 2023-07-10
 */
@RestController
@RequestMapping("/archive/yqPgg")
public class YqPggController extends BaseController
{
    @Autowired
    private IYqPggService yqPggService;

    /**
     * 查询盘规格列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqPgg:list')")
    @GetMapping("/list")
    public TableDataInfo list(YqPgg yqPgg)
    {
        startPage();
        List<YqPgg> list = yqPggService.selectYqPggList(yqPgg);
        return getDataTable(list);
    }

    /**
     * 导出盘规格列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqPgg:export')")
    @Log(title = "盘规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqPgg yqPgg)
    {
        List<YqPgg> list = yqPggService.selectYqPggList(yqPgg);
        ExcelUtil<YqPgg> util = new ExcelUtil<YqPgg>(YqPgg.class);
        util.exportExcel(response, list, "盘规格数据");
    }

    /**
     * 获取盘规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:yqPgg:query')")
    @GetMapping(value = "/{pggId}")
    public AjaxResult getInfo(@PathVariable("pggId") Long pggId)
    {
        return success(yqPggService.selectYqPggByPggId(pggId));
    }

    /**
     * 新增盘规格
     */
    @PreAuthorize("@ss.hasPermi('archive:yqPgg:add')")
    @Log(title = "盘规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqPgg yqPgg)
    {
        return success(yqPggService.insertYqPgg(yqPgg));
    }

    /**
     * 修改盘规格
     */
    @PreAuthorize("@ss.hasPermi('archive:yqPgg:edit')")
    @Log(title = "盘规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqPgg yqPgg)
    {
        return success(yqPggService.updateYqPgg(yqPgg));
    }

    /**
     * 删除盘规格
     */
    @PreAuthorize("@ss.hasPermi('archive:yqPgg:remove')")
    @Log(title = "盘规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pggIds}")
    public AjaxResult remove(@PathVariable Long[] pggIds)
    {
        return success(yqPggService.deleteYqPggByPggIds(pggIds));
    }

    /**
     * 解除组盘状态
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqPgg:cancel')")
    @Log(title = "组盘记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/cancel/{pggId}")
    public AjaxResult cancel(@PathVariable Long pggId)
    {
        return success(yqPggService.cancel(pggId));
    }

    /**
     * 查询组盘记录列表（查看详情）
     */
    @PreAuthorize("@ss.hasPermi('archive:yqPgg:zpjlList')")
    @GetMapping("/zpjlList/{pggId}")
    public AjaxResult selectYqZpjlListByPgg(@PathVariable("pggId") Long pggId){
        List<Map<YqZpjl,List<YqZpmx>>> plan = yqPggService.selectYqZpjlListByPgg(pggId);
        return AjaxResult.success(JSONObject.toJSON(plan));
    }
}
